package com.hz.house.dao;

import com.hz.house.bean.entity.HouseCertHistory;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;

import java.util.Date;
import java.util.List;

@Mapper
public interface HouseCertHistoryMapper {
    /**
     * 按周查询开盘记录
     * @param date
     * @return
     */
    @Select("SELECT id, building_id buildingId, building_name buildingName, house_count houseCount, area_name areaName, price_info priceInfo, fix_info fixInfo, week_day_start weekDayStart " +
            "FROM qb_huose_cert_history WHERE TO_DAYS(week_day_start) = TO_DAYS(#{date})")
    List<HouseCertHistory> listCertHistory(@Param("date")Date date);

    /**
     * 统计周开盘记录
     * @param start
     * @param end
     * @return
     */
    @Select("SELECT i.fd_buildingId buildingId, b.fd_name buildingName, (s.fd_pgHouseNum + s.fd_gxHouseNum + s.fd_gxHouseNum) houseCount , \n" +
            "b.fd_showPrice priceInfo,  i.fd_decorationType fixInfo, bl.fd_areaName areaName\n" +
            "FROM building_open_info i \n" +
            "LEFT JOIN building_open_info_housing_information s ON i.fd_id=s.fd_openId \n" +
            "LEFT JOIN building b ON i.fd_buildingId=b.fd_id \n" +
            "LEFT JOIN building_location bl ON bl.fd_buildingId = i.fd_buildingId\n" +
            "WHERE i.fd_presellTime >= #{start} AND i.fd_presellTime <= #{end} GROUP BY i.fd_buildingId")
    List<HouseCertHistory> selectForDate(@Param("start") Date start, @Param("end") Date end);

    /**
     * 插入统计信息
     * @param bean
     */
    @Insert("INSERT INTO qb_huose_cert_history(building_id, building_name, house_count, area_name, price_info, fix_info, week_day_start)\n" +
            "VALUES(#{buildingId}, #{buildingName}, #{houseCount}, #{areaName}, #{priceInfo}, #{fixInfo}, #{weekDayStart})")
    void inser(HouseCertHistory bean);
}
